package com.lqd.mall.system.repository;

import com.lqd.mall.interaction.system.SysPostEntity;
import com.lqd.mall.interaction.system.vo.PostVo;
import com.lqd.mall.jpa.repository.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author 零起点
 * @create 2022-03-22 23:18
 */
public interface SysPostRepository extends BaseRepository<SysPostEntity,Long> {

 @Query(value =  "SELECT p.post_id as post_id,p.post_name as post_name,p.post_code as post_code" +
         " FROM sys_post p " +
         " LEFT JOIN sys_user_post up ON up.post_id = p.post_id " +
         " LEFT JOIN sys_user u ON u.user_id = up.user_id " +
         " WHERE u.user_id = :userId",nativeQuery = true)
    List<PostVo> selectPostsByUserId(@Param("userId") Long userId);
}
